package com.girl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class GirlController {
    @Autowired
    private GirlRepository girlRepository;
    @Autowired
    private TransService transService;
    @RequestMapping(value = "/girlList",method = RequestMethod.GET)
    public List<Girl> girlList(){
        return  girlRepository.findAll();
    }

    @PostMapping(value = "/addGirl")
    public Girl girlAdd(@RequestParam("age") int age,@RequestParam("cupSize") String cupSize){
        Girl girl = new Girl();
        girl.setAge(age);
        girl.setCupSize(cupSize);
        Girl girl1 = girlRepository.save(girl);
        return girl1;
    }

    @PostMapping("/deleteGirl")
    public void deleteGirl(@RequestParam("id") int id){
        Girl girl = new Girl();
        girl.setId(id);
        girlRepository.delete(girl);
    }

   @RequestMapping(value = "/updateGirl",method = RequestMethod.PUT)
    public Girl updateGirl(@RequestParam("id") int id,@RequestParam(value = "age")int age,@RequestParam(value = "cupSize")String cupSize){
        Girl girl =new Girl();
        girl.setId(id);
        girl.setAge(age);
        girl.setCupSize(cupSize);
        return  girlRepository.save(girl);
    }

    @RequestMapping(value = "/selectByAge",method = RequestMethod.GET)
    public List<Girl> selectByAge(@RequestParam("age") int age){
       return girlRepository.getGirlByAge(age);
    }

    @GetMapping("/testTrans")
    public void testTrans(){
        transService.insertTwo();
    }
}
